//
//  CZQHomeStudyDetailVC.m
//  coachmanage
//
//  Created by 众拳科技 on 2018/3/23.
//  Copyright © 2018年 众拳科技. All rights reserved.
//

#import "CZQHomeStudyDetailVC.h"
#import "WLScrollView.h"
#import "textView.h"
#import "CZQStudentExeViewController.h"
@interface CZQHomeStudyDetailVC ()<WLScrollViewDelegate,UIScrollViewDelegate>

@property(nonatomic,weak)WLScrollView *WLScollView;

@property(nonatomic,weak)UIPageControl * page;

@end

@implementation CZQHomeStudyDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"学员案例";
    
    self.view.backgroundColor = BackGroundColor;
    
    
    [self creatUI];
    // Do any additional setup after loading the view.
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    
    [self loadMemberDataList];
    
}

#pragma mark - 懒加载
-(NSMutableArray *)studyArrM
{
    if (!_studyArrM) {
        
        _studyArrM = [NSMutableArray array];
        
    }
    
    return _studyArrM;
}

-(NSMutableArray *)dataArr
{
    if (_dataArr) {
        _dataArr = [NSMutableArray array];
    }
    return _dataArr;
}

-(void)creatUI
{
    WLScrollView *view = [[WLScrollView alloc]initWithFrame:CGRectMake(5, 0, kScreenWidth -10, kScreenHeight-adaptNavagationBar)];
    view.delegate = self;
    view.isAnimation = YES;
    view.scale = 0.85;
    view.marginX = 0;
    view.maxAnimationScale = 1;
    view.minAnimationScale = 0.9;
    view.backgroundColor = BackGroundColor;
    [self.view addSubview:view];
    self.WLScollView = view;
    [self.WLScollView starRender];
    
    UIPageControl * page = [UIPageControl new] ;
    
    //设置背景颜色
    page.backgroundColor = [UIColor clearColor];
    
    //设置小圆圈的个数
    page.numberOfPages = self.studyArrM.count;
    
    //设置 小圆圈的颜色
    page.pageIndicatorTintColor = [UIColor grayColor];
    
    //设置当前页的小圆圈颜色
    page.currentPageIndicatorTintColor = [UIColor redColor];
    
    page.userInteractionEnabled = NO;
    
    //获取/更改当前页
    page.currentPage = 0;
    
    [self.view addSubview:page];
    self.page = page;
    
    [page mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.width.mas_equalTo(self.view);
        
        make.bottom.mas_equalTo(self.view).offset(-CZQ_SaferTabbarHeight - 10);
        
        make.height.mas_equalTo(50);
        
    }];
    
}

#pragma mark - 学员案例列表

-(void)loadMemberDataList
{
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    
    
    [params setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"ShopID"] forKey:@"ShopID"];
    
    [params setObject:@1 forKey:@"page"];
    
    [params setObject:@100 forKey:@"rows"];
    
    
    
    [HTTPTool GET:Get_GetMemberCaseListData parameters:params
     
          success:^(id responseObject){
              
              [MBProgressHUD hideHUDForView:self.view];
              
              NSLog(@"%@",responseObject);
              
              if (responseObject && [[responseObject objectForKey:@"Code"] intValue] == 0) {
                  
                  NSArray *resultArr = [responseObject objectForKey:@"rows"];
                  
                  [self.studyArrM removeAllObjects];
                  
                  self.studyArrM = [NSMutableArray arrayWithArray:resultArr];
                  
                  
                  [self.WLScollView reloadInputViews] ;
                  
                  self.page.numberOfPages = self.studyArrM.count;
              }
              
              
          }
     
          failure:^(NSError *error){
              
              [MBProgressHUD hideHUDForView:self.view];
          }];
    
}


#pragma mark - WLScrollViewDelegate
-(NSInteger)numOfContentViewScrollView:(WLScrollView *)scrollView
{
    return self.studyArrM.count;
}

-(WLSubView *)scrollView:(WLScrollView *)scrollView subViewFrame:(CGRect)frame cellAtIndex:(NSInteger)index
{
    WS(weakSelf);
    
    NSDictionary *dic = self.studyArrM[index];
    
//    static NSString *cellID = @"cell";
//    textView *studyView = (textView *)[scrollView dequeueReuseCellWithIdentifier:cellID];
//    if (!studyView) {
//       studyView = [[textView alloc]initWithFrame:frame Identifier:cellID];
//    }
    textView *studyView = [[textView alloc]initWithFrame:frame Identifier:nil];
    
    studyView.eidtBtn.tag = index;
    
    [studyView.eidtBtn addTarget:self action:@selector(eidt:)];
    
    studyView.dic = dic;

    return studyView;
    
}

-(void)scrollView:(WLScrollView *)scrollView didSelectedAtIndex:(NSInteger)index
{
    
    
}

-(void)scrollView:(WLScrollView *)scrollView didCurrentCellAtIndex:(NSInteger)index
{
    self.page.currentPage = index;
    NSLog(@"当前显示的%ld",index);
}

#pragma mark - 编辑
-(void)eidt:(UIButton *)sender
{
    NSDictionary *dic = self.studyArrM[sender.tag];
    
    CZQStudentExeViewController *study = [CZQStudentExeViewController new];
    
    study.dicDat = dic;
    
    [self.navigationController pushViewController:study animated:YES];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
